﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CoreHelper.Validation.Validators
{
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
    public class DateValidatorAttribute : BaseValidatorAttribute
    {
        public DateValidatorAttribute() : this(ValidationUtils.Messages.Date)
        {
        }

        public DateValidatorAttribute(string errorMessage) : base(errorMessage)
        {
        }
        public override bool IsValid(object value)
        {
            if (value == null) return false;
            if (value is DateTime || value is DateTime?) return true;
            DateTime dt;
            return DateTime.TryParse(value.ToString(), out dt);
        }
    }
}
